package com.xueyi.system.BaseCropGrowth.manager.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xueyi.system.BaseCropGrowth.domain.query.BaseCropGrowthQuery;
import com.xueyi.system.BaseCropGrowth.domain.dto.BaseCropGrowthDto;
import com.xueyi.system.BaseCropGrowth.domain.po.BaseCropGrowthPo;
import com.xueyi.system.BaseCropGrowth.domain.model.BaseCropGrowthConverter;
import com.xueyi.system.BaseCropGrowth.mapper.BaseCropGrowthMapper;
import com.xueyi.common.web.entity.manager.impl.BaseManager;
import com.xueyi.system.BaseCropGrowth.manager.IBaseCropGrowthManager;
import com.xueyi.system.parcel.domain.po.BaseParcelPo;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

/**
 * 作物长势管理 数据封装层处理
 *
 * @author xueyi
 */
@Component
public class BaseCropGrowthManager extends BaseManager<BaseCropGrowthQuery, BaseCropGrowthDto, BaseCropGrowthPo, BaseCropGrowthMapper, BaseCropGrowthConverter> implements IBaseCropGrowthManager {


    /**
     * 查询日期范围
     * @return
     */

    @Override
    public List<BaseCropGrowthDto> findDatelist() {

        Date date = new Date();
        List<BaseCropGrowthPo> findByList = baseMapper.selectList(
                Wrappers.<BaseCropGrowthPo>query().lambda()
                        .le(BaseCropGrowthPo::getPlantStartTime, date)
                        .ge(BaseCropGrowthPo::getPlantEndTime, date));
                        /*.apply("date_format (plant_start_time,'%Y-%m-%d') <= date_format('" + date + "','%Y-%m-%d')")
                        .apply( "date_format (plant_end_time,'%Y-%m-%d') >= date_format('" + date + "','%Y-%m-%d')"));*/
        return baseConverter.mapperDto(findByList);
    }
}
